import Router from 'vue-router';
import Vue from 'vue';
Vue.use(Router);

export default new Router({
    mode: 'history',
    routes: [{
            path: '/',
            redirect: '/product'
        },

        {
            path: '/product',
            // 路由对应组件
            component: () => import('@/views/product/index'),
            redirect: '/product/list',
            // 配置子路由
            children: [{
                    path: 'list',
                    component: () => import('@/views/product/children/list')
                },
                {
                    // 1.动态路由
                    path: 'detail/:productId',
                    component: () => import('@/views/product/children/detail')
                }
            ]
        },
        {
            path: '/classify',
            component: () => import('@/views/classify/index')
        },
        {
            path: '/cart',
            component: () => import('@/views/cart/index')
        },
        {
            path: '/submit',
            component: () => import('@/views/submit/index')
        },
        {
            path: '/pay',
            component: () => import('@/views/pay/index')
        },
        {
            path: '/my',
            name: 'my',
            redirect: '/my/person',
            component: () => import('@/views/my/index'),
            children: [{
                    path: 'person',
                    component: () => import('@/views/my/children/person')
                },
                {
                    path: 'setting',
                    component: () => import('@/views/my/children/setting')
                },
                {
                    path: 'login',
                    component: () => import('@/views/my/children/login')
                }
            ]
        },
        {
            path: '/demo',
            component: () => import('@/components/Demo')
        },
        {
            path: '*',
            component: () => import('@/components/NotFound')
        }
    ],
    scrollBehavior(to, from, savedPosition) { // 解决vue页面之间跳转，页面不是在顶部的问题
        return {
            x: 0,
            y: 0
        }
    }
});